define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var ShellImpl = require('$UI/system/lib/portal/shellImpl');
	
	require("$UI/system/lib/cordova/cordova");
//	require("cordova!cordova-plugin-screen-orientation");
	
	var Model = function(){
		this.callParent();
		this.serverUrl = "http://www.xjzlhy.com:81";
		var shellImpl = new ShellImpl(this, {
			"contentsXid" : "pages",
			"pageMappings" : {
				"main":{
					url : '$UI/communityOto/mainActivity.w'
				},
				
				"login":{
					url:"$UI/communityOto/mine/login.w"
				},
				"category":{
					url:"$UI/communityOto/categoryFregment.w"
				}
				
				
			}
		});
	};

	Model.prototype.modelLoad = function(event){
	
     
		justep.Shell.showPage("main");
        
        if('lockOrientation' in window.screen){
        	window.screen.lockOrientation('portrait');
        }
		

	};
	
	//获取用户类型
	Model.prototype.getUserType = function(){
		return JSON.parse(localStorage.getItem("userInfo")).userType;
	};
	
	//获取用户名
	Model.prototype.getUserName = function(){
	    console.log(JSON.parse(localStorage.getItem("userInfo")));
		return JSON.parse(localStorage.getItem("userInfo")).userName;
	};
	//获取用户电话
	Model.prototype.getUserPhone = function(){
		return JSON.parse(localStorage.getItem("userInfo")).phone;
	};
	//获取用户地址
	Model.prototype.getUserAddress = function(){
		return JSON.parse(localStorage.getItem("companyInfo")).address;
	};
	
	//获取用户ID
	Model.prototype.getUserId = function(){
	    
		return JSON.parse(localStorage.getItem("userInfo")).userId;
	
	};
	
	//获取社区名称
	Model.prototype.getCompanyName = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).name;
	
	};
	
	//获取社区ID
	Model.prototype.getCompanyId = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).id;
	
	};
	
	
	//获取社区地址
	Model.prototype.getCompanyAddress = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).address;
	
	};
	
	//获取社区邮编
	Model.prototype.getCompanyCode = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).code;
	
	};
	
	
	//获取小区ID
	Model.prototype.getOfficeId = function(){
	    if(!localStorage.getItem("officeInfo")){
	    	return null;
	    }
		return JSON.parse(localStorage.getItem("officeInfo")).id;
	
	};
	
	
	
	//获取商家介绍
	Model.prototype.getBusnessIntroduce = function(){
	   // console.log(JSON.parse(localStorage.getItem('userInfo')).data[0].userBusiness.introduce);
		return JSON.parse(localStorage.getItem('userInfo')).userBusiness.introduce;
	};
	
	//获取商家图片
	Model.prototype.getBusinessImage = function(){
	    var imageArray = null;
	    if('images' in JSON.parse(localStorage.getItem('userInfo')).userBusiness){
	    	var imageStr = JSON.parse(localStorage.getItem('userInfo')).userBusiness.images;
	    	
			if(imageStr){
			   imageStr = imageStr.substr(1);
				imageArray = imageStr.split('|');
			    
			}
			
	    }
		
		
		
		return imageArray;
	
	};
	
	

	
	
	//判断用户是否登录
	Model.prototype.isLogin = function(){
		return localStorage.getItem('userInfo')?true:false;
	
	};
	
	//验证手机号码格式
	Model.prototype.testMobile = function(mobile){
		var pattern = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
		return pattern.test(mobile);
	
	};

	return Model;
});